package com.tencet.servlet;

import com.tencet.entity.OpenAccount;
import com.tencet.service.Impl.UserServiceImpl;
import com.tencet.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: aiming    @date: 2022/7/22 19:22
 * @description:
 */

@WebServlet("/type")
public class TypeServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String phoneNum = req.getParameter("phoneNum");
        UserServiceImpl userService = new UserServiceImpl();
        Integer accType = userService.getAccTypeByPhone(phoneNum);
        if (accType != null){
            OpenAccount openAccount = userService.getSecondAccountNumberByPhone(phoneNum);
            String secondAccountNumber = openAccount.getSecondAccountNumber();
            //把二类账户号存入session
            req.getSession().setAttribute("secondAccountNumber",secondAccountNumber);
            //将开户对象存入session,以键值对的形式
            req.getSession().setAttribute("openAccount",openAccount);
        }
        resp.getWriter().write(accType+"");
    }
}
